package com.quectel.pay.module.merchant.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.quectel.pay.module.merchant.dao.PayCertFileDao;
import com.quectel.pay.module.merchant.dto.PayCertFileDto;
import com.quectel.pay.module.merchant.entity.PayCertFileEntity;
import com.quectel.pay.module.merchant.service.PayCertFileService;
import com.quectel.util.common.CopyUtils;
import com.quectel.util.kit.Snowflake;
import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author ryan
 * @date 2021-04-26 17:27:23
 */
@DubboService
public class PayCertFileServiceImpl implements PayCertFileService {

    private static final Logger LOGGER = LoggerFactory.getLogger(PayCertFileServiceImpl.class);

    @Autowired
    private PayCertFileDao payCertFileDao;


    @Override
    public PayCertFileDto selectByCode(String sha1Code) {
        PayCertFileEntity payCertFileEntity = payCertFileDao.selectOne(new QueryWrapper<PayCertFileEntity>().eq("sha1_code", sha1Code).last("limit 1"));
        return CopyUtils.copyObj(payCertFileEntity, PayCertFileDto.class);
    }

    @Override
    public List<PayCertFileDto> queryList(Map<String, Object> params) {
        List<PayCertFileEntity> list = payCertFileDao.queryList(params);
        return CopyUtils.copyList(list, PayCertFileDto.class);
    }

    @Override
    public int queryTotal(Map<String, Object> params) {
        return payCertFileDao.queryTotal(params);
    }

    @Override
    public Long save(PayCertFileDto dto) {
        PayCertFileEntity entity = CopyUtils.copyObj(dto, PayCertFileEntity.class);
        entity.setId(Snowflake.nextId());
        payCertFileDao.insert(entity);
        return entity.getId();
    }

    @Override
    public void updateById(PayCertFileDto dto) {
        PayCertFileEntity entity = CopyUtils.copyObj(dto, PayCertFileEntity.class);
        payCertFileDao.updateById(entity);
    }

    @Override
    public PayCertFileDto selectById(Long id) {
        PayCertFileEntity entity = payCertFileDao.selectById(id);
        return CopyUtils.copyObj(entity, PayCertFileDto.class);
    }

    @Override
    public void deleteById(Long id) {
        payCertFileDao.deleteById(id);
    }

    @Override
    @Transactional
    public void deleteBatch(Long[] ids) {
        for (Long id : ids) {
            deleteById(id);
        }
    }
}
